package com.lovo.csc.service.impl;

import com.lovo.csc.entity.Frozen;
import com.lovo.csc.mapper.FrozenMapper;
import com.lovo.csc.service.IFrozenService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.dto.TranslateDto;
import com.lovo.util.MQUtil;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lovo
 * @since 2022-07-12
 */
@Service
public class FrozenServiceImpl extends ServiceImpl<FrozenMapper, Frozen> implements IFrozenService {

    @Autowired
    IFrozenService service;
    @RabbitListener(queues = MQUtil.frozenQueue)
    public void order(Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag, TranslateDto dto) throws Exception {
        if(null!=dto) {
            Frozen order = new Frozen();
            order.setFName( dto.getUserName());
            order.setFPhone(dto.getUserPhone());
            order.setFRealname(dto.getRealName());
            order.setFGender(dto.getUserSex());
            order.setFZiimg(dto.getUserQualification());
            order.setFShimg(dto.getUserCard());
            order.setFCompany(dto.getUserPompany());
            order.setFGrade(dto.getGrade());
            order.setFState(dto.getState());
            service.save(order);
        }
        channel.basicAck(tag,false);
    }

//
    @Override
    public void updateFrozenState(String name, String state) {
        baseMapper.updateFrozenState(name,state);
    }
}